package com.heima.article.listener;

import com.alibaba.fastjson.JSON;
import com.heima.article.service.ApArticleService;
import com.heima.common.constants.message.HotArticleConstants;
import com.heima.model.mess.app.ArticleVisitStreamMess;
import com.xxl.job.core.biz.model.ReturnT;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class ArticleIncrHandleListener {
    @Autowired
    ApArticleService apArticleService;

    @KafkaListener(topics = HotArticleConstants.HOTARTICLE_INCR_HANDLE_OUPUT_TOPIC)
    public ReturnT<String> hotArticleHandler(String message) {
        log.info("获取行为数据及次数 {}", message);
        //调用方法计算行为得分更新redis数据
        apArticleService.updateApArticle(JSON.parseObject(message,ArticleVisitStreamMess.class));
        log.info("获取行数为数据计算得分更新redis方法结束============");
        return ReturnT.SUCCESS;
    }
}
